package com.etogc.groupchat.login.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.etogc.groupchat.R;
import com.etogc.groupchat.base.BaseActivity;
import com.etogc.groupchat.login.biz.LoginBiz;
import com.etogc.groupchat.login.biz.LoginHttpBiz;

/**
 * 忘记密码
 */
public class ForgetActivity extends BaseActivity {

    private EditText etTel;
    private EditText etVerify;
    private EditText etPwd;
    private EditText etRePwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget);
        etTel = findViewById(R.id.etTel);
        etVerify = findViewById(R.id.etVerify);
        etPwd = findViewById(R.id.etPwd);
        etRePwd = findViewById(R.id.etRePwd);
        findViewById(R.id.btnReset).setOnClickListener(listener);
        findViewById(R.id.tvGetVerify).setOnClickListener(listener);
        setTitle("重置密码");
        showBack();
    }

    private View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.btnReset:
                    requestReset();
                    break;
                case R.id.tvGetVerify:
                    requestSms();
                    break;
            }

        }
    };

    private void requestSms() {
        String tel = etTel.getText().toString();
        LoginHttpBiz.getSms(this, tel);
    }


    //需要服务端返回token
    private void requestReset() {
        String tel = etTel.getText().toString();
        String verify = etVerify.getText().toString();
        String pwd = etPwd.getText().toString();
        String rePwd = etRePwd.getText().toString();
        boolean isCheckOk = LoginBiz.checkInput(tel, verify, pwd, rePwd);
        if (isCheckOk) {
            LoginHttpBiz.reset(this, tel, verify, pwd, rePwd);
        }
    }


}
